package com.yao.shop.context;
import com.yao.shop.pojo.SysLog;
import lombok.Data;

/**
 * 本地线程上下文
 * 用来存储在同一个线程中可能会用到的全局变量
 *
 * @author 杨德石
 */
@Data
public class SystemContext {

    /**
     * 日志实体
     */
    private SysLog sysLog;


    /**
     * 线程本地内存中的变量
     */
    private static ThreadLocal<SystemContext> threadLocal = new ThreadLocal<>();

    public static SystemContext get() {
        if (threadLocal.get() == null) {
            SystemContext systemContext = new SystemContext();
            systemContext.setSysLog(new SysLog());
            threadLocal.set(systemContext);
        }
        return threadLocal.get();
    }

    public void remove() {
        threadLocal.remove();
    }
}
